package ma.controller.panels;

import javax.swing.JComboBox;

import ma.controller.gui.Controllable;
import ma.controller.panels.auxillary.CtrInformationPanel;
import ma.controller.panels.auxillary.MMComboBoxListener;
import ma.model.EBenchmarkInterface;
import ma.model.ManufacturingMethodInterface;
import ma.view.gui.ChooseMethods;
import ma.view.gui.EBenchmarkPanel;

/**
 * The {@code CtrChooseMethods} controls the behavior of the
 * {@code ChooseMethods} panel.
 * @author Oliver Eckstein
 *
 */
public class CtrChooseMethods implements Controllable {
    private ChooseMethods panel;
    private EBenchmarkInterface eBenchmark;
    private CtrInformationPanel infoPanelController;
    
    /**
     * To create a new instance of a {@code CtrChooseMethods} and connect it
     * to the model and the controller of the information panel.
     * @param eBenchmark the application's model.
     * @param infoPanelController the controller of the information panel.
     */
    public CtrChooseMethods(EBenchmarkInterface eBenchmark,
            CtrInformationPanel infoPanelController) {
        this.eBenchmark = eBenchmark;
        this.infoPanelController = infoPanelController;
        createPanel();        
    }
    
    /**
     * To create the controller's panel as follows:
     * First, get all implemented manufacturing types of this EBenchmark.
     * Then translate them into German and create the panel.
     */
    private void createPanel() {
        int i = 0;
        String[] manuMethods =
                new String[ManufacturingMethodInterface.SubType.values()
                           .length];
        for(ManufacturingMethodInterface.SubType manuMethod : 
                ManufacturingMethodInterface.SubType.values()) {
            manuMethods[i++] = eBenchmark.typeToString(manuMethod);
        }
        panel = new ChooseMethods(manuMethods, infoPanelController);

        for(JComboBox<Integer> cb : panel.getComboBoxes()) {
            cb.addActionListener(new MMComboBoxListener(
                    eBenchmark,
                    cb,
                    infoPanelController));
        }
    }
    
    @Override
    /*
     * (non-Javadoc)
     * @see ma.controller.gui.Controllable2#getView()
     */
    public EBenchmarkPanel getView() {
        return panel;
    }
}
